/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.p.narcissus.ui;

import java.io.File;

import com.google.code.p.narcissus.core.NarcissusException;
import com.google.code.p.narcissus.core.model.ComparisonResult;
import com.google.code.p.narcissus.core.screenshots.PictureComparisonMapper;

/**
 * Acts as a storage of any information related to a specific test run, helping
 * using this information in the ui.
 * <p>
 *  The fact that this class extends <code>TestReference</code> is of big importance.
 *  the additions that come from this are heavily used when Narcissus works in
 *  comparison mode.
 * </p>
 * @author jadoj
 */
public class TestRun extends TestReference{
    private File comparisonXML;
    private File comparisonScreenshot;
    private ComparisonResult comparison;

    public TestRun(File comparisonXMLFile, File referenceScreenshot) throws NarcissusException {
        super(referenceScreenshot);
        this.comparisonXML = comparisonXMLFile;

        if(this.comparisonXML == null){
            throw new NarcissusException(TestRun.class.getName() + ".testRunFileCannotBeNullEx");
        }

        this.comparison = PictureComparisonMapper.fromXml(this.comparisonXML);

        File comparisonShot = new File(comparisonXMLFile.getAbsolutePath().replaceAll(".xml", ".png"));
        this.comparisonScreenshot = comparisonShot.exists() ? comparisonShot : referenceScreenshot;
    }

    public File getComparisonScreenshot() {
        return comparisonScreenshot;
    }

    public File getComparisonXML() {
        return comparisonXML;
    }

    public ComparisonResult getComparison() {
        return comparison;
    }

    @Override
    public String toString(){
        return comparisonXML.getName().substring(0, comparisonXML.getName().length() - 4);
    }
}
